Normalize speaker output, using an FIR filter in an RPvdsEx circuit created in MATLAB

Tech Note: TN0966
Product: RPvdsEx, SigCalRP
Version: All
Date Added: 2014-12-16

Issue

This article explains how to use SigCalRP and MATLAB to generate FIR coefficients, then use them in RPvdsEx to filter signals that will be played out to a speaker.

To generate your coefficients follow these three steps:

  1. Use SigCalRP to measure the transfer function (TF) of the system.

  2. Export calibration data in CSV format.

  3. Use a MATLAB script to convert the CSV file into a set of filter coefficients.

The FIR coefficients generated in this example, can be used to filter signals of varying frequency and constant amplitude so that the sound output in units of dB SPL from the speaker will be constant over all frequencies. These coefficients will be generated for a circuit running at a specific sampling frequency. To work properly, they must be used in a circuit running at the same sampling frequency.

Measuring the TF of the system

SigCalRP can be used to calculate the TF of a system for speaker calibration at sample rates up to 200 kHz. Before performing this operation, users should know the A/D and D/A conversion limitations of their specific hardware. For example, the RZ6 maximum sampling rate is 195312.50 for both signal production and acquisition. The figure below shows a typical setup using a single RZ6.

Under Signal Setup in SigCalRP, enter the frequency step using the number of frequencies you wish to measure across the spectrum and the Nyquist frequency. For an RZ6 running at 200 KHz and a filter of 200 points, the Nyquist frequency is 97656.25 Hz and the frequency start and frequency step are determined by the relationship:

97656.25/200 = 488.28125 Hz

Run SigCalRP at 200 kHz to ensure that the Nyquist frequency of the device running the FIR (97656.25 Hz) is represented. Also, make sure that all test frequencies used are integer multiples of the Nyquist frequency of the device to avoid aliasing.

Set the horizontal green bar in the calibration plot to the dB level you want to achieve for all frequencies using the filter. The filter will attenuate frequencies above the green bar and amplify frequencies below it. Use care when amplifying the signal. Typically, only frequencies that will not be presented should be amplified.

To export the data as a *.csv file, select Export Calibration Data on the Calibrate menu.

Creating the filter coefficients

Next, download and extract the compressed (.zip) SigCalRP Example files from the TDT website at SigCalRPExamples.zip.

Use the provided MATLAB script (RZ6SigCalFIR.m) to convert the CSV file into a set of FIR coefficients. Your output will be a .txt file that can be used with RPvdsEx.

Loading the filter coefficients

Add FIR and SourceFile components to the signal generation segment of your RPvdsEx circuit as shown below.

Update the SourceFile component to point to the .txt file generated by the MATLAB script. Any signal that passes through that FIR component will be normalized.

A sample CSV file and several circuit files are included in the Example folder for demonstration purposes.